﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data.SqlClient;

public class tbConfigDB
{
    #region[tbConfig_Add]
    public static bool tbConfig_Add(tbConfigDATA _tbConfigDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbConfig_Add", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@coMaxPoint", _tbConfigDATA.coMaxPoint));
                dbCmd.Parameters.Add(new SqlParameter("@coStatus", _tbConfigDATA.coStatus));
                dbCmd.Parameters.Add(new SqlParameter("@coPointNV", _tbConfigDATA.coPointNV));
                dbCmd.Parameters.Add(new SqlParameter("@coPointLD", _tbConfigDATA.coPointLD));
                dbCmd.Parameters.Add(new SqlParameter("@coTotal", _tbConfigDATA.coTotal));
                dbCmd.Parameters.Add(new SqlParameter("@coPoitType", _tbConfigDATA.coPoitType));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbConfig_Update]
    public static bool tbConfig_Update(tbConfigDATA _tbConfigDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbConfig_Update", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@coId", _tbConfigDATA.coId));
                dbCmd.Parameters.Add(new SqlParameter("@coMaxPoint", _tbConfigDATA.coMaxPoint));
                dbCmd.Parameters.Add(new SqlParameter("@coStatus", _tbConfigDATA.coStatus));
                dbCmd.Parameters.Add(new SqlParameter("@coPointNV", _tbConfigDATA.coPointNV));
                dbCmd.Parameters.Add(new SqlParameter("@coPointLD", _tbConfigDATA.coPointLD));
                dbCmd.Parameters.Add(new SqlParameter("@coTotal", _tbConfigDATA.coTotal));
                dbCmd.Parameters.Add(new SqlParameter("@coPoitType", _tbConfigDATA.coPoitType));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbConfig_GetAll]
    public static List<tbConfigDATA> tbConfig_GetAll()
    {
        List<tbConfigDATA> list = new List<tbConfigDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbConfig_GetAll", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbConfigDATA objtbConfigDATA = new tbConfigDATA(
                        reader["coId"].ToString(),
                        reader["coMaxPoint"].ToString(),
                        reader["coStatus"].ToString(),
                        reader["coPointNV"].ToString(),
                        reader["coPointLD"].ToString(),
                        reader["coTotal"].ToString(),
                        reader["coPoitType"].ToString());
                        list.Add(objtbConfigDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
}
